/*    This file is part of libepistle.
 *
 *    libepistle is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU Lesser General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    libepistle is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public License
 *    along with libepistle.  If not, see <http://www.gnu.org/licenses/>.
 */


#ifndef EPISTLE_MSGR_H
#define EPISTLE_MSGR_H

#include <primo/map.h>

#include "message.h"

typedef Map Msgrs;

typedef struct {
	int fd;
	List inbox;
	Msg *wip;
	void *extra;
} Msgr;

int
msgrs_init(Msgrs *msgrs, Disposer *dspr, Err *err);

void
msgrs_dispose(Msgrs *msgrs);

Msgr *
msgr_add(Msgrs *msgrs, uint32_t key_len, const void *key,
	 int fd, int epoll_fd, void *extra, Err *err);

int
msgr_remove(Msgrs *msgrs, uint32_t key_len, const void *key,
	    void **extra, Err *err);

Msgr *
msgr_get(Msgrs *msgrs, uint32_t key_len, const void *key);

int
msgr_recv(Msgr *msgr, uint32_t max_len, int wait, Err *err);

int
msgr_post(Msgr *msgr, Msg *msg, Err *err);

int
msgr_send(Msgr *msgr, int epoll_fd, int wait, Err *err);

#endif
